package com.kingsystem.kingteachermarks_backend.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

import com.kingsystem.kingteachermarks_backend.KingUtil.StringOper;

@Controller
@CrossOrigin
public class UploadFiles {
    @RequestMapping("/upload")
    @ResponseBody
    public String upload(MultipartFile file) throws IOException {
        String fileName = file.getOriginalFilename();
        String fileNameTime = StringOper.getCurrenTimeStringForFileName();

        String uploadPath = StringOper.getConfigInfo("uploadPath");
        String filePath = uploadPath + fileNameTime + "_" + fileName;
//        long fileSize = file.getSize();
        file.transferTo(new File(filePath));
        return fileNameTime;
    }
}
